﻿using AutoMapper;
using MediatR;
using S.Parturition.API.Application.Command;
using S.Parturition.Domain.Model;
using S.Parturition.Infrastructure.Interface;

namespace S.Parturition.API.Application.CommandHandlers
{
    public class UpdateLambRegistrationHandler : IRequestHandler<UpdateLambRegistrationCommand, bool>
    {

        private readonly ILambRegistrationRepository lambRegistration;

        private readonly IMapper mapper;

        public UpdateLambRegistrationHandler(ILambRegistrationRepository lambRegistration, IMapper mapper)
        {
            this.lambRegistration = lambRegistration;
            this.mapper = mapper;
        }

        public async Task<bool> Handle(UpdateLambRegistrationCommand request, CancellationToken cancellationToken)
        {
            LambRegistrationModel lamb = mapper.Map<LambRegistrationModel>(request);
            lamb.UpdateDate = DateTime.Now;

            return await lambRegistration.UpdateAsync(lamb);
        }
    }
}
